import { Post } from "@/lib/models";
import { NextResponse } from "next/server";

export const GET = async (request) => {
  try {
    const posts = await Post.find();
    return NextResponse.json(posts);
  } catch (error) {
    throw new Error(error);
  }
};

export const POST = async (request) => {
  const res = await request.json();

  try {
    const posts = await new Post(res).save();
    return NextResponse.json(posts);
  } catch (error) {
    throw new Error(error);
  }
};
